package com.crr.mall.search.controller;

import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.to.es.SkuEsModel;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RequestMapping("/search/save")
@RestController
public class ElasticSearchController extends BaseController {
    @Autowired
    ProductSaveService productSaveService;
    @PostMapping("/product")
    public ResultBean productSearch(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean b=false;
        try {
           b = productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
           return fail("商品上架异常");
        }
        if(b){
            return fail("商品上架失败");
        }
        return success("商品正常上架");
    }
}
